package fem2.observer;

import fem2.Observer;
import fem2.strategies.Strategy;

public class TimeStepObserver implements Observer {

	private Strategy s;
	private double timeStep = 0.0;

	public TimeStepObserver() {
		s = null;
	}

	public TimeStepObserver(Strategy s) {
		this.s = s;
		s.addObserver(this); // make sure this observer is added first
	}

	public double getCurrentTimeStep() {
		return timeStep;
	}

	@Override
	public void fireStarted() {
	}

	@Override
	public void fireTimeStepStarted() {
	}

	@Override
	public void fireIterationStarted() {
	}

	@Override
	public void fireIterationFinished() {
	}

	@Override
	public void fireTimeStepFinished() {
		if (s == null) {
			timeStep++;
		} else {
			timeStep = s.getCurrentTimeStep();
		}
	}

	@Override
	public void fireFinished() {
	}

}
